package m.appserver;

import m.system.util.StringUtil;
import m.system.util.SystemUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class AppServerUtil {

	/**
	 * 加载配置文件
	 *  path 空则加载默认配置文件
	 *  name
	 * 
	 *  FileNotFoundException
	 */
	public static InputStream loadConfig(String path,String name) throws FileNotFoundException {
		if(StringUtil.isSpace(path)) return loadConfig(name);
		File file=new File(path+name);
		if(file.exists()) {
			SystemUtil.printlnIf(true,"读取配置文件: ",file.getPath());
			return new FileInputStream(file);
		}else {
			return null;
		}
	}
	/**
	 * 加载默认配置文件
	 *  name
	 * 
	 */
	public static InputStream loadConfig(String name) {
		SystemUtil.printlnIf(true,"读取配置文件: ",Thread.currentThread().getContextClassLoader().getResource(name).getPath());
		return Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
	}
}
